<template>
  <el-dialog :title="title" v-if="open" v-model="open" width="1200px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="90px" :inline="true" @submit.native.prevent>
      <el-form-item label="查询条件:" prop="goodsName">
        <el-input v-model="queryParams.goodsName" placeholder="请输入商品名称" @keyup.enter="handleQuery"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery">搜索</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-card class="box-card" shadow="always">
      <el-table ref="table" v-loading="loading" :data="dataSource" @selection-change="handleSelectionChange"
        @row-click="rowClick" :row-key="getRowKey">
        <el-table-column type="selection" width="55" align="center" :selectable="selectHandle"
          :reserve-selection="true" />
        <el-table-column label="#" type="index" width="55" align="center"> </el-table-column>
        <el-table-column label="商品图片" align="center" width="120">
          <template #default="scope">

            <ImagePreview :width="100" :height="100" :src="scope.row.packImg" :preview-src-list="[scope.row.packImg]" />
          </template> </el-table-column>>

        <el-table-column label="商品名称" align="left" prop="goodsName" min-width="200" />
        <el-table-column label="商品分类" align="center" prop="classifyName" width="150">
          <template #default="scope">
            {{ scope.row.classifyName }}
          </template>
        </el-table-column>

        <!-- <el-table-column label="商品来源" align="center" prop="goodsType" width="150">
          <template #default="scope">
            {{ selectDictLabel(goods_source, scope.row.goodsType) }}
          </template>
        </el-table-column> -->
        <el-table-column label="商品品牌" align="center" prop="brandName" />
        <!-- <el-table-column label="商品规格" align="center" prop="goodsSize" /> -->
        <el-table-column label="代发" align="center" prop="supplyMode">
          <template #default="scope">
            {{ selectDictLabel(drop_shipping, scope.row.supplyMode) }}
          </template>
        </el-table-column>
        <el-table-column label="上架状态" align="center" width="200">
          <template #default="scope">
            {{ selectDictLabel(material_audit_status, scope.row.auditStatus || '') }}
          </template>
        </el-table-column>
        <el-table-column label="集采成本价" align="center" prop="costPrice" />
        <el-table-column label="批发价" align="center" prop="wholesalePrice" />
      </el-table>

      <pagination v-show="total > 0" :total="total" v-model:page.sync="queryParams.pageNum"
        v-model:limit.sync="queryParams.pageSize" @pagination="getList" />
    </el-card>

    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submit">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import listMixin from '@/mixins/listMixin';
import ImagePreview from '@/components/ImagePreview/index.vue';
export default {
  name: "selectMaterialForm",
  mixins: [listMixin],
  components: {
    ImagePreview
  },
  data() {
    return {
      open: false,
      title: "选择商品",
      loading: false,
      goods_source: [],
      drop_shipping: [],
      material_audit_status: [],//商品审核状态

      queryParams: {//查询条件
        pageNum: 1,
        pageSize: 10,
        auditStatus: 1,
      },
      urls: {
        list: '/order/goods/list',
        delete: '/order/goods',
      }
    }
  },

  methods: {
    show() {
      this.open = true;
      this.getDicts(['goods_source', 'material_audit_status', 'drop_shipping'])
      this.getList()
    },
    submit() {
      this.$emit('ok', this.selectedRows)
      this.open = false;
    },
    cancel() {
      this.open = false;
    },
    getRowKey(row) {
      return row.id;
    },
    rowClick(row, column, event) {
      this.$refs.table.toggleRowSelection(row);
    },
  }
}
</script>

<style lang="scss" scoped></style>